package examine;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Vector;

/**
 * 用于检测data文件夹下list文件的目录是否正确
 * 如
 *   actionlist.vw 对应的data/action文件夹下的数据
 * @author Administrator
 *
 */
public class textlist {
	private static String urls[]= {"./data/action","./data/animation","./data/block","./data/character","./data/event","./data/item"
			,"./data/map","./data/monster","./data/plot","./data/tank"};
	private static Vector<String> error=new Vector<>();
	public static void main(String[] args) {
		System.out.println("开始检测...");
		error=new Vector<>();
		for(int i=0;i<urls.length;i++)testlist(urls[i]);
		System.out.println("检测结束.\n");
		System.out.println("检测结果:");
		if(error.size()>0) {
			for(int i=0;i<error.size();i++)System.out.println(error.get(i));
			System.out.println("共"+error.size()+"个数据问题.");
		}else {
			System.out.println("未出现问题.");
		}
	}
	private static void testlist(String url) {
		try{
			File fs=new File(url);
			BufferedReader re=new BufferedReader(new FileReader(new File(url+"list.vw")));
			String a[]=fs.list();
			Vector<String> aa=new Vector<>();
			for(String i:a)if(aa.indexOf(i)<0)aa.add(i);
			String b;
			while((b=re.readLine())!=null) {
				if(aa.indexOf(b.replaceAll("\n", "").replaceAll(" ", ""))>-1) {
					System.out.println("检测"+url.split("/")[2]+":"+b+" 正常.");
					aa.remove(b);
				}else {
					System.out.println("检测"+url.split("/")[2]+":"+b+" 数据不存在.");
					error.add("检测"+url.split("/")[2]+":"+b+" 数据不存在.");
				}
			}
			re.close();
			if(aa.size()>0) {
				for(int i=0;i<aa.size();i++) {
					System.out.println("检测"+url.split("/")[2]+":"+aa.get(i)+" 目录未添加.");
					error.add("检测"+url.split("/")[2]+":"+aa.get(i)+" 目录未添加.");
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
}
